USER_OB = class("USER_OB")
USER_OB:inherit(F_COMN_DBASE)
USER_OB:inherit(F_CHAR_COMM)
USER_OB:inherit(F_CHAR_SAVE)
USER_OB:inherit(F_CHAR_LEVEL)
USER_OB:inherit(F_CHAR_ITEM)
USER_OB:inherit(F_CHAR_ROOM)
USER_OB:inherit(F_CHAR_COMBAT)
USER_OB:inherit(F_CHAR_UPDATE)

function USER_OB:set_id(user_id)
    return self:set_temp("user_id", user_id)
end

function USER_OB:get_id()
    return self:query_temp("user_id")
end

function USER_OB:set_team_id(team_id)
    return self:set_temp("team_id", team_id)
end

function USER_OB:get_team_id()
    return self:query_temp("team_id") or 0
end

function USER_OB:get_team_invite()
    return self:query_temp("team_invite") or {}
end

function USER_OB:check_team_invite(user_id)
    local invite = self:get_team_invite()
    for _, _user_id in pairs(invite) do
        if _user_id == user_id then
            return true
        end
    end
    return false
end

function USER_OB:team_invite_del_one(user_id)
    local invite = self:get_team_invite()
    for _id, _user_id in pairs(invite) do
        if _user_id == user_id then
            invite[_id] = nil
            self:set_temp("team_invite", invite)
            return true
        end
    end
    return false
end

function USER_OB:team_invite_add_one(user_id)
    local invite = self:get_team_invite()
    table.insert(invite,user_id)
    self:set_temp("team_invite", invite)
end

function USER_OB:set_agent(agent)
    self:set_temp("agent", agent)
    -- 更新用户基本信息
    self:set_steam_id(agent:get_user_name()) --user_name 就是 steam_id
    self:set_user_name(agent:get_user_name()) --user_name 就是 steam_id
    self:set_nick_name(agent:get_nick_name())
    self:set_avatar_url(agent:get_avatar_url())
    return
end

function USER_OB:get_agent()
    return self:query_temp("agent")
end

function USER_OB:remove_agent()
    return self:delete_temp("agent")
end

function USER_OB:set_user_name(user_name)
    return self:set("user_name", user_name)
end

function USER_OB:get_user_name()
    local user_name = self:query("user_name")
    if not user_name then
        return self:query_temp("loginInfo", "user_name") or ""
    end
    return user_name
end

function USER_OB:set_nick_name(nick_name)
    return self:set("nick_name", nick_name)
end

function USER_OB:get_nick_name()
    local nick_name = self:query("nick_name")
    if not nick_name then
        return self:query_temp("loginInfo", "nick_name") or ""
    end
    return nick_name
end

function USER_OB:set_avatar_url(avatar_url)
    return self:set("avatar_url", avatar_url)
end

function USER_OB:get_avatar_url()
    local avatar_url = self:query("avatar_url")
    if not avatar_url then
        return self:query_temp("loginInfo", "avatar_url") or ""
    end
    return avatar_url
end

---! Steam ID
function USER_OB:set_steam_id(steam_id)
    return self:set("steam_id", steam_id)
end

function USER_OB:get_steam_id()
    return self:query("steam_id") or self:get_id()
end

---! 胜场
function USER_OB:set_victory(victory)
    return self:set("victory", victory)
end

---! 胜场
function USER_OB:get_victory()
    return self:query("victory")
end

---! 胜率
function USER_OB:set_victory_rate(victory_rate)
    return self:set("victory_rate", victory_rate)
end

---! 胜率
function USER_OB:get_victory_rate()
    return self:query("victory_rate")
end

---! 击毁坦克数量
function USER_OB:set_tank_num(tank_num)
    return self:set("tank_num", tank_num)
end

---! 击毁坦克数量
function USER_OB:get_tank_num()
    return self:query("tank_num") or 0
end

function USER_OB:add_tank_num(tank_num)
    return self:set("tank_num", self:get_tank_num() + tank_num)
end


---! 选择的坦克
function USER_OB:set_tank_id(tank_id)
    return self:set("tank_id", tank_id)
end

---! 选择的坦克
function USER_OB:get_tank_id()
    return self:query("tank_id") or 1
end

function USER_OB:generate_player_info()
    local data = {}
    data.user_id = self:get_id()
    data.user_name = self:get_user_name()
    return data
end

---! 成为机器人
function USER_OB:become_robot()
    return self:set_temp("robot", true)
end

---! 是否是机器人
function USER_OB:is_robot()
    return self:query_temp("robot") or false
end
